home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / OrgPlus 7 SBE / ORGPL.CAB / toolbarFunc.js < prev    next >
Encoding:
JavaScript  |  2007-05-15  |  12.2 KB  |  496 lines

  1. /**********************************************************
  2. *                                                         *
  3. * (C) Copyright 2002 - 2004,  Human Concepts (tm)         *
  4. *                                                         *
  5. ***********************************************************
  6. * File name: toolbarFunc.js                               *
  7. * Author: Andrey Ponomarev                                *
  8. **********************************************************/
  9.  
  10.   var zoomValue = 1.0;
  11.   var bZoomOnWheel = false;
  12.   var oOverwiewWnd;
  13.   var bZoomInitReady = false;
  14.  
  15.   var AdditionalButtons = ( parent.isEnableSave() ? 1 : 0 ) + ( parent.isEnablePrint() ? 1 : 0 );
  16.   if( AdditionalButtons > 0 ) AdditionalButtons++; // separator
  17.  
  18.   var nSaveButtonNumber      = ( parent.isEnableSave() ? 1 : 0 );
  19.   var zoomInButton           = 0 + AdditionalButtons;
  20.   var nZoomCombo             = 2 + AdditionalButtons;
  21.   var nZoomFitButtonNumber   = 3 + AdditionalButtons;
  22.   var nZoomWheelButtonNumber = 4 + AdditionalButtons;
  23.  
  24.   window.onunload = doUnload;
  25.  
  26.   var strZoomSupportMsg = "To fully support OrgPlus HTML Zoom functionality,\n\ryou will need to upgrade your Internet Explorer to\n\rat least version 5.5" //Loc
  27.  
  28.   function doUnload()
  29.   {
  30.     if ( typeof(oOverwiewWnd) == "object" && !oOverwiewWnd.closed)
  31.     {
  32.       oOverwiewWnd.close()
  33.     }
  34.   }
  35.  
  36.   function buttonIn_onclick() 
  37.   {
  38.     ClearAutoFitFlag()
  39.     DoZoomIn()
  40.   }
  41.  
  42.   function ClearAutoFitFlag()
  43.   {
  44.     if (getIEVersion() >= 5.5 && typeof(oToolBar) != 'undefined')
  45.       oToolBar.getItem(nZoomFitButtonNumber).setAttribute('selected', 'false')
  46.   }
  47.  
  48.   function SetAutoFitFlag()
  49.   {
  50.     if (getIEVersion() >= 5.5 && typeof(oToolBar) != 'undefined')
  51.       oToolBar.getItem(nZoomFitButtonNumber).setAttribute('selected', 'true')
  52.   }
  53.  
  54.   function buttonOut_onclick() 
  55.   {
  56.     ClearAutoFitFlag()
  57.     DoZoomOut()
  58.   }
  59.   
  60.   function onclick_Save()  {
  61.     window.open( GetOpxPath(), "_blank", "status=no,toolbar=no,menubar=no,location=no" );
  62.   }
  63.   
  64.   function GetOpxPath()   {
  65.     return parent.GetOpxPath();
  66.   }
  67.   
  68.  
  69.   function setZoomExt(zoomVal) 
  70.   {
  71.     if( getIEVersion() < 5.5 )
  72.     {
  73.       alert(strZoomSupportMsg );
  74.       return;
  75.     }
  76.     
  77.     if( zoomVal > 0)
  78.     { 
  79.       switchScrolling(true);
  80.       setZoom(zoomVal);
  81.     }
  82.     else
  83.         ZoomToFit();
  84.   }
  85.  
  86.   function buttonZoomToFit_onclick()
  87.   { 
  88.     if (getIEVersion() < 5.5)
  89.     {
  90.       alert(strZoomSupportMsg);
  91.       return;
  92.     }
  93.     ZoomToFit();
  94.     tryCenterPage();
  95.   }
  96.  
  97.   function ZoomToFitInit()
  98.   {
  99.     if (getIEVersion() < 5.5)
  100.     {
  101.       tryCenterPage()
  102.       updateOverviewWindow()
  103.     }
  104.     else
  105.     {
  106.       if (!bZoomInitReady)
  107.       {
  108.         DoZoomToFitInit()
  109.         bZoomInitReady = true        
  110.       }
  111.       else
  112.       {
  113.         ClearAutoFitFlag()
  114.         setZoom(zoomValue)
  115.       }        
  116.     }
  117.   }
  118.   
  119.   function HitTestReaction()
  120.   {
  121.     //alert('hit test')//onClickGroup()
  122.   }
  123.     
  124.   function UpdateHitTestRectsByZoom()
  125.   {
  126.     if (!isSelectionEnabled())
  127.       return
  128.  
  129.     var st_strRectForHitTestName = "_HitTestRect" 
  130.     var groupObjs = parent.hcMain.PageGroup.document.getElementsByTagName("group")
  131.     var zoomValue = parseFloat(parent.hcMain.PageGroup.style.zoom)
  132.     if (zoomValue == 0.0)
  133.       zoomValue = 0.01
  134.     for (i = 0; i < groupObjs.length; i++)
  135.     {
  136.       var objGroup = groupObjs[i]
  137.       if (objGroup.id == "PageGroup")
  138.         continue
  139.         
  140.           var strName = objGroup.id + st_strRectForHitTestName
  141.           var bFound = false
  142.       var elem
  143.           for (j = 0; j < objGroup.children.length; j++)
  144.           {
  145.               if (objGroup.children[j].id == strName)
  146.               {
  147.                 elem = objGroup.children[j]
  148.                 bFound = true
  149.                 break
  150.               }
  151.           }
  152.         
  153.           if (!bFound)//if not found - create
  154.       {
  155.         elem = objGroup.document.createElement("v:rect")
  156.         elem.id = strName
  157.         elem.style.top = 0
  158.         elem.style.left = 0
  159.         elem.setAttribute("stroked", "false") 
  160.         //elem.setAttribute("filled", "false") 
  161.         
  162.         //elem.onclick = HitTestReaction
  163.         
  164.         var fill = objGroup.document.createElement("v:fill")
  165.         fill.setAttribute("color", "#009000")          
  166.         fill.setAttribute("opacity", ".0")
  167.     
  168.         objGroup.appendChild(elem)
  169.         elem.appendChild(fill);
  170.       }
  171.       
  172.       if (typeof(elem) == "object")
  173.       {
  174.         var k = 1. / zoomValue;
  175.         var m = objGroup.style.pixelWidth
  176.         if (k > 1)
  177.           m = m * k
  178.         else 
  179.           m = 0
  180.         elem.style.width = m
  181.         
  182.         m = objGroup.style.pixelHeight
  183.         if (k > 1)
  184.           m = m * k
  185.         else 
  186.           m = 0
  187.         elem.style.height = m
  188.       }      
  189.     }
  190.   }
  191.     
  192.   function onZoomCombo()
  193.   {
  194.     ClearAutoFitFlag()
  195.     var obj = event.srcElement
  196.     setZoomExt(obj.value)
  197.     parent.hcMain.focus()
  198.   }
  199.  
  200.   function buttonPrint_onclick()
  201.   {
  202.     window.open( parent.hcMain.location.href, "_blank", "_blank","height=200,width=760px,status=no,toolbar=no,menubar=yes,location=no");
  203.   }
  204.  
  205.   function buttonOverview_onclick()
  206.   {
  207.     if ( typeof(oOverwiewWnd) == "undefined" || 
  208.          typeof(oOverwiewWnd) == "object" && oOverwiewWnd.closed )
  209.     {
  210.       var objMain = parent.hcMain
  211.       if ( typeof(objMain) != "object" || typeof(objMain.PageGroup) != "object" )
  212.       {
  213.         //onOverviewClosed()
  214.         alert("Sorry, can't display Overview Window - Chart document is not loaded yet") //Loc
  215.         return         
  216.       }
  217.  
  218.       oOverwiewWnd = window.showModelessDialog("overviewWnd.html", window, 
  219.          "dialogHide=yes; center=no; help=no; dialogLeft=500; dialogTop=30; status=no; dialogHeight:10; dialogWidth:14; resizable:no; scroll:no; edge:sunken");
  220.     }
  221.     else
  222.     {
  223.       oOverwiewWnd.close()
  224.     }
  225.   }
  226.  
  227.   function onOverviewWndCreated() 
  228.   {
  229.     initOverviewWindow()
  230.     updateOverviewWindow()
  231.   }
  232.  
  233.   function updateOverviewWindow()
  234.   {
  235.     if ( typeof(oOverwiewWnd) == "object" && !oOverwiewWnd.closed)
  236.     {
  237.       oOverwiewWnd.draw(parent.hcMain)
  238.     }
  239.   }
  240.  
  241.   function initOverviewWindow()
  242.   {
  243.     if ( typeof(oOverwiewWnd) == "object" && !oOverwiewWnd.closed)
  244.     {
  245.       var objMain = parent.hcMain
  246.       if (typeof(objMain) == "object")
  247.       {
  248.         var objPageGroup = objMain.document.getElementById("PageGroup")
  249.         if (typeof(objPageGroup) == "object")
  250.         {
  251.           var strImg = objMain.strImageForPreview
  252.           if ( typeof(strImg) == 'undefined' )
  253.             strImg = ""
  254.           oOverwiewWnd.initPage( objPageGroup, strImg )
  255.         }
  256.       }
  257.     }
  258.   }
  259.  
  260.   function buttonShowHidePanels_onclick()
  261.   {
  262.     if (parent.isShowPanelsEnable())
  263.     {
  264.       parent.bHidePanelsByDefault = !parent.bHidePanelsByDefault;
  265.       parent.DoHideShowPanels();
  266.     }
  267.   }
  268.  
  269.   function buttonZoomOnWheel_onclick()
  270.   {
  271.     bZoomOnWheel = !bZoomOnWheel
  272.     var ver = getIEVersion()
  273.     if (bZoomOnWheel && ver < 6.0)
  274.       alert("You should Update Internet Explorer to Version 6.0 or higher\r\nto have Zoom on Mouse Wheel") //Loc 
  275.   }
  276.  
  277.   function onChartMouseWheeling(evnt)
  278.   {
  279.     if (bZoomOnWheel)
  280.     {
  281.       if (evnt.wheelDelta >= 120)
  282.       {
  283.         buttonIn_onclick()
  284.       }
  285.       else if (evnt.wheelDelta <= -120)
  286.       {
  287.         buttonOut_onclick()
  288.       }
  289.     }
  290.   }
  291.  
  292.   function HumanConcepts_onclick() 
  293.   {
  294.     parent.location = "http://www.humanconcepts.com"
  295.   }
  296.  
  297.   function isSelectionEnabled()
  298.   {
  299.     return (parent.bIndexPage || parent.bCountPage || parent.bProfilePage)
  300.   }
  301.  
  302.   function tryCenterPage()
  303.   {
  304.     var obj = parent.hcMain.document.body; //.all.PageGroup;
  305.     var wndHeight = parseInt(obj.clientHeight);
  306.     var wndWidth = parseInt(obj.clientWidth);
  307.  
  308.     var oPage = parent.hcMain.PageGroup;
  309.     if (typeof(oPage) != "object")
  310.       return;
  311.  
  312.     oPage.style.visibility = 'hidden';
  313.  
  314.     var nZoomValue = 1.
  315.     if (getIEVersion() >= 5.5)
  316.       nZoomValue = zoomValue
  317.  
  318.     var pageHeight = oPage.style.pixelHeight * nZoomValue
  319.     var pageWidth = oPage.style.pixelWidth * nZoomValue
  320.  
  321.     var nLeft = 0
  322.     if (wndWidth > pageWidth)
  323.       nLeft = (wndWidth - pageWidth) / 2
  324.  
  325.     var nTop = 0
  326.     if (wndHeight > pageHeight)
  327.       nTop = (wndHeight - pageHeight) / 2
  328.  
  329.     oPage.style.left = parseInt(nLeft)
  330.     oPage.style.top = parseInt(nTop)
  331.  
  332.     oPage.style.visibility = 'visible'
  333.  
  334.   } 
  335.  
  336.   function DoZoomIn()
  337.   {
  338.     if (zoomValue < 3)
  339.     {
  340.       if (zoomValue < 0.25)  
  341.         zoomValue = 0.25;
  342.       else if (zoomValue < 0.5)  
  343.         zoomValue = 0.5;        
  344.       else if (zoomValue < 0.75)  
  345.         zoomValue = 0.75;
  346.       else if (zoomValue < 1.0)  
  347.         zoomValue = 1.0;
  348.       else if (zoomValue < 1.25)  
  349.         zoomValue = 1.25;
  350.       else if (zoomValue < 1.5)  
  351.         zoomValue = 1.5;
  352.       else if (zoomValue < 1.75)  
  353.         zoomValue = 1.75;
  354.       else if (zoomValue < 2.0)  
  355.         zoomValue = 2.0;
  356.       else if (zoomValue < 2.25)  
  357.         zoomValue = 2.25;
  358.       else if (zoomValue < 2.5)  
  359.         zoomValue = 2.5;
  360.       else if (zoomValue < 2.75)  
  361.         zoomValue = 2.75;
  362.       else if (zoomValue < 3.0)  
  363.         zoomValue = 3.0;
  364.         
  365.       setZoomExt(zoomValue);
  366.     }
  367.   }
  368.  
  369.   function DoZoomOut()
  370.   {
  371.     if (zoomValue > 0.25)
  372.     {
  373.       if (zoomValue > 3.0)  
  374.         zoomValue = 3.0;
  375.       else if (zoomValue > 2.75)  
  376.         zoomValue = 2.75;
  377.       else if (zoomValue > 2.5)  
  378.         zoomValue = 2.5;
  379.       else if (zoomValue > 2.25)  
  380.         zoomValue = 2.25;
  381.       else if (zoomValue > 2.0)  
  382.         zoomValue = 2.0;
  383.       else if (zoomValue > 1.75)  
  384.         zoomValue = 1.75;
  385.       else if (zoomValue > 1.5)  
  386.         zoomValue = 1.5;
  387.       else if (zoomValue > 1.25)  
  388.         zoomValue = 1.25;
  389.       else if (zoomValue > 1.0)  
  390.         zoomValue = 1.0;
  391.       else if (zoomValue > 0.75)  
  392.         zoomValue = 0.75;
  393.       else if (zoomValue > 0.5)  
  394.         zoomValue = 0.5;        
  395.       else if (zoomValue > 0.25)  
  396.         zoomValue = 0.25;
  397.  
  398.  
  399.       setZoomExt(zoomValue);
  400.     }
  401.   }
  402.  
  403.   function setZoom(value)
  404.   {
  405.     zoomValue = parseFloat(value)
  406.     //var tmpInt = parseInt( (parseFloat(value) + 0.01) * 10) //to avoid bug with float value
  407.     //zoomValue = tmpInt / 10
  408.     if (zoomValue < 0.0)
  409.     {
  410.       zoomValue = Math.abs(zoomValue);
  411.       bFitToWindow = true;  
  412.     }
  413.     else 
  414.     {
  415.       bFitToWindow = false;
  416.       if (zoomValue < 0.25)
  417.         zoomValue = 0.25;
  418.     }
  419.  
  420.     var item2 = toolbarButtons.rows[0].cells[ nZoomCombo ].childNodes[0];
  421.     if (typeof(item2) == 'object' && typeof(item2.setAttribute) != 'undefined')
  422.     {
  423.       if (bFitToWindow == false)
  424.         item2.setAttribute('value', zoomValue)
  425.       else
  426.         item2.setAttribute('value', 0)        
  427.     }
  428.  
  429.     var obj = parent.hcMain.PageGroup
  430.  //   var bg  = parent.hcMain.document.body.childNodes[0];
  431.     if (typeof(obj) == "object")
  432.     {
  433.       obj.style.visibility = 'hidden';
  434.       obj.style.zoom = zoomValue;
  435. //      if( typeof( bg ) == "object" && zoomValue > 0.75 )
  436. //        bg.style.zoom = zoomValue;
  437.       obj.style.visibility = 'visible';
  438.     }
  439.  
  440.     tryCenterPage()
  441.     
  442.     UpdateHitTestRectsByZoom()
  443.  
  444.     updateOverviewWindow()
  445.   }
  446.  
  447.   function switchScrolling(b)
  448.   {  
  449.     var obj = parent.hcMain.document.body
  450.     if(b)
  451.       obj.setAttribute("scroll","auto"); 
  452.     else
  453.       obj.setAttribute("scroll","no"); 
  454.   }
  455.       
  456.   function ZoomToFit()
  457.   {
  458.     var obj = parent.hcMain.document.body; //parent.hcMain.frameElement
  459.     if( !obj ) return;
  460.     
  461.     var wndHeight = parseInt(obj.clientHeight) 
  462.     var wndWidth = parseInt(obj.clientWidth)
  463.  
  464.     var oPage = parent.hcMain.PageGroup
  465.     if (typeof(oPage) != "object")
  466.       return
  467.     
  468.     switchScrolling(false)
  469.     oPage.style.visibility = 'hidden';
  470.  
  471.     var pageHeight = oPage.style.pixelHeight + 20
  472.     var pageWidth = oPage.style.pixelWidth + 20      
  473.  
  474.     var d = wndHeight / pageHeight
  475.     if (pageWidth * d > wndWidth )
  476.     d = wndWidth / pageWidth
  477.  
  478.     if (getIEVersion() < 5.5)
  479.     {
  480.       tryCenterPage()
  481.       updateOverviewWindow()
  482.     }
  483.     else
  484.     {   
  485.       setZoom(-d)
  486.     }
  487.  
  488.     oPage.style.visibility = 'visible';    
  489.   }
  490.  
  491.   function DoZoomToFitInit()
  492.   {
  493.     ZoomToFit()
  494.   }
  495.  
  496.